const path = require('path');
const Bree = require('bree');

const bree = new Bree({
  root: path.join(__dirname, '..', 'jobs'),
  workerMessageHandler: function (msg) {
    const jobName = msg.name;
    // 延迟引入，避免循环依赖
    const reminder = require('./reminder');
    if (reminder.checkReminderName(msg.name)) {
      // 因为要调用实例，所以BREE_CONF没法隔离
      bree.remove(jobName).then(() => console.log(`提醒任务${msg.name}已移除`));
    }
  },
  outputWorkerMetadata: true
});
module.exports = bree;